home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_04 / 9n04078a < prev    next >
Text File  |  1991-02-17  |  2KB  |  64 lines

  1. /********************************************************************/
  2. /*        Test byte and word classes.  Copyright Joe Schell 1989.      */
  3. /********************************************************************/
  4.  
  5. #include <byte.hpp>
  6.  
  7. #define comp(c,i)    ( ((c) == int(i)) ? "okay.\n" : "not okay.\n")
  8.  
  9. void test_init(int c)  {cout << "   Initialization is " << comp(c,3);}
  10. void test_inc(int c)   { cout << "   Increment is " << comp(c,4); }
  11. void test_dec(int c)   { cout << "   Decrement is " << comp(c,3); }
  12. void test_eql(int c)   { cout << "   Equal for int is " << comp(c,3);}
  13.  
  14.  
  15. main()
  16. {
  17.     cout << "Testing byte and word class.\n";
  18.  
  19.     byte b, c=3, *d;
  20.     char *test_byte = "abc";
  21.  
  22.     cout << "Byte:( should be 03, result=" << c.make_string() << ")\n";
  23.     test_init(c);
  24.     c++;    test_inc(c);
  25.     c--;    test_dec(c);
  26.     b=c;    test_eql(b);
  27.     c=4;
  28.     cout << "   Setting equal to integer is " << comp(c,4);
  29.  
  30.     b=c;
  31.     c++;
  32.     cout << "   Comparison of bytes is "
  33.          << ((b!=c) ? "okay." : "not okay.") << "\n";
  34.     d = (byte*)test_byte;
  35.     cout << "   Pointing is " << comp(*d,*test_byte);
  36.     d++;
  37.     cout << "   Incrementing pointer is " << comp(*d,*(test_byte+1));
  38.  
  39.  
  40.     word x, y=3, *z;
  41.     int test_word=8;
  42.     cout << "\nWord:( should be 0003, result=" 
  43.          << y.make_string() << ")\n";
  44.     test_init(y);
  45.     y++;    test_inc(y);
  46.     y--;    test_dec(y);
  47.     x=y;    test_eql(x);
  48.     y++;
  49.     cout << "   Comparison of words is "
  50.         << ((x!=y) ? "okay." : "not okay.") << "\n";
  51.     z = (word*)(&test_word);
  52.     cout << "   Pointer to word is " << comp(*z,test_word);
  53.     (*z)++;
  54.     cout << "   Dereference and increment is " << comp(*z,9);
  55.  
  56.     // The next two lines should cause 'Illegal values' when
  57.     // not commented.
  58.     // b=UCHAR_MAX + 1;
  59.     // x=(long)UINT_MAX + 1;
  60.  
  61.     cout << "\nTest is finished.\n";
  62. }
  63.  
  64.